package com.rst.dao;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.rst.model.ExamGroups;

@Repository
@Transactional
public class ExamGroupsDAO {

	@Autowired
	private SessionFactory sessionFactory;
	
	public void saveExamGroups(ExamGroups examGroups) {
		sessionFactory.getCurrentSession().save(examGroups);	
		
	}

	public ExamGroups getExamGroupsById(Long examGroupsId) {
	    Session session = sessionFactory.getCurrentSession();
	    ExamGroups examGroups = (ExamGroups)session.get(ExamGroups.class, examGroupsId);
		return examGroups;
	}

	@SuppressWarnings("unchecked")
	public List<ExamGroups> getExamGroupsList() {
		Session session = sessionFactory.getCurrentSession();
	    String str = "FROM ExamGroups eg WHERE eg.status = :status  ";
	    	
	    Query query = session.createQuery(str);
	    query.setParameter("status",  ExamGroups.ACTIVE);
		return query.list();
	}

	public void updateExamGroups(ExamGroups examGroups) {
		sessionFactory.getCurrentSession().update(examGroups);
		
	}
}




